//
//  ViewController.m
//  Map
//
//  Created by 周成龙 on 16/10/12.
//  Copyright © 2016年 ZCL. All rights reserved.
//

#import "ViewController.h"

@import MapKit;

@import CoreLocation;

@interface ViewController ()<MKMapViewDelegate>

@property (nonatomic, strong) MKMapView *mapView;
@property (nonatomic, strong) CLLocationManager *locationM;

@end

@implementation ViewController

/** 位置管理者 */
- (CLLocationManager *)locationM
{
    if (!_locationM) {
        _locationM = [[CLLocationManager alloc] init];
        if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
            [_locationM requestAlwaysAuthorization];
        }
    }
    return _locationM;
}


- (MKMapView *)mapView {
    if (nil == _mapView) {
        _mapView = [[MKMapView alloc] init];
        _mapView.frame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64);
        _mapView.mapType = MKMapTypeStandard;
        // 显示用户的位置
        _mapView.showsUserLocation = YES;
        //        _mapView.userLocation.title = @"上海市";
        //        _mapView.userLocation.subtitle = @"杨浦区大学路";
        [self locationM];
        _mapView.delegate = self;
    }
    return _mapView;
}
//- (MKMapView *)mapView
//{
//    if (!_mapView) {
//        _mapView = [[MKMapView alloc] init];
//        _mapView.frame = self.view.bounds;
//        
//        _mapView.delegate = self;
//        _mapView.mapType = MKMapTypeStandard;
//        
//        _mapView.showsCompass = YES;
//        // 比例尺
//        _mapView.showsScale = YES;
//        // 显示交通
//        _mapView.showsTraffic = YES;
//        // 兴趣点
//        _mapView.showsPointsOfInterest = YES;
//        // 建筑物
//        _mapView.showsBuildings = YES;
//        _mapView.showsUserLocation = YES;
//    }
//    return _mapView;
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self.view addSubview:self.mapView];
    
}

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    /**
     *  MKUserLocation  大头针数据模型
     *  其实, 喊什么都行, 只不过, 这个类, 遵循了大头针数据模型, 必须遵循的一个协议 MKAnnotation
     location : 当前的位置数据模型
     heading : 当前朝向
     title : 标题
     subtitle : 子标题
     */
    userLocation.title = @"小码哥";
    userLocation.subtitle = @"大神武器";
    
    // 显示当前地图的中心, 在哪个具体的经纬度坐标
    // 不会自动放大地图比例
    //    [self.mapView setCenterCoordinate:userLocation.location.coordinate animated:YES];
    
    
    CLLocationCoordinate2D centerCoordinate = userLocation.location.coordinate;
    MKCoordinateSpan span = MKCoordinateSpanMake(0.027023, 0.018108);
    MKCoordinateRegion region = MKCoordinateRegionMake(centerCoordinate,span);
    // 设置地图显示区域
    [self.mapView setRegion:region animated:YES];
}

-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    NSLog(@"%f---%f", mapView.region.span.latitudeDelta, mapView.region.span.longitudeDelta);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
